package com.learnyou.server.xingzuo.dto.common;

import io.swagger.annotations.ApiModelProperty;

import java.util.Objects;

public class PageRequestDTO {
    @ApiModelProperty(value = "每页大小")
    Integer pageSize;

    @ApiModelProperty(value = "当前页")
    Integer pageNum;

    public PageRequestDTO() {
        this.pageSize = 20;
        this.pageNum = 1;
    }

    public PageRequestDTO(Integer pageSize, Integer pageNum) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public static PageRequestDTO of(Integer pageSize, Integer pageNum) {
        return new PageRequestDTO(pageSize, pageNum);
    }


    public Integer getPageSize() {
        Integer size = 20;
        if (Objects.nonNull(pageSize) && pageSize<100 && pageSize > 0) {
            size = pageSize;
        }
        return size;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        Integer num = 1;
        if (Objects.nonNull(pageNum) && pageNum<100 && pageNum > 0) {
            num = pageNum;
        }
        return num;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }
}
